package com.pandora.common.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author developer
 */
public class DateUtil {
    private static String SDF_DEFAULT = "yyyy-MM-dd HH:mm:ss";
    private static String SDF_YMD = "yyyy.MM.dd";
    public static String getFormatDateTime(){
        SimpleDateFormat sdf = new SimpleDateFormat(SDF_DEFAULT);
        Date currentTime = new Date();
        String dateString = sdf.format(currentTime);
        return dateString;
    }

    public static Timestamp getNowTimestamp(){
        return new Timestamp(System.currentTimeMillis());
    }

    public static String getDateStr(Timestamp timestamp){
        return timestamp.toString().replace("-", "").replace(" ", "");
    }

    public static String getYMDPointStr(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat(SDF_YMD);
        if(date == null){
            return "";
        }
        return sdf.format(date);
    }

    public static Date getYMDPointDate(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(SDF_YMD);
        if(date != null){
            String dateStr = sdf.format(date);
            try {
                Date d = sdf.parse(dateStr);
                return d;
            } catch (ParseException e) {
                return null;
            }
        }
        return null;
    }
}
